package com.leecode;

public class Leet283 {
	public static void main(String[] args) {
//		new Leet283().moveZeroes(new int[]{0,1,0,3,12});
		new Leet283().moveZeroes(new int[]{0});

	}
	//12%,自已想的,
	public void moveZeroes(int[] nums) {
		if(nums.length==0)return;

		int moveB=nums.length-1;
		int moveE=moveB;

		while(moveB>=0){
			if(nums[moveB]!=0){
				moveB--;
				continue;
			}

			for(int a=moveB;a<moveE;a++){
				nums[a]=nums[a+1];
			}
			nums[moveE]=0;
			moveE--;
			moveB--;
		}
	}

	/**
	 * 100%,89%
	 * 考点:利用index为0++,赋盖index0,赋盖idx1,赋盖idx2...
	 * @param nums
	 */
	public void moveZeroes2(int[] nums) {
		if(nums.length==0 || nums.length==1)return;

		int idx=0;
		for(int a=0;a<nums.length;a++){
			if(nums[a]!=0 ){
				if(a>idx){//不写就bug
					nums[idx++]=nums[a];
					nums[a]=0;
				}else{
					idx++;
				}
			}
		}
	}
}
